Dynamic compensation of stray electric fields in an ion trap using machine learning and adaptive algorithm

Surface ion traps are among the most promising technologies for scaling up quantum computing machines, but their complicated multi-electrode geometry can make some tasks, including compensation for stray electric fields, challenging both at the level of modeling and of practical implementation. Here we demonstrate the compensation of stray electric fields using a gradient descent algorithm and a machine learning technique, which trained a deep learning network. We show automated dynamical compensation tested against induced electric charging from UV laser light hitting the chip trap surface. The results show improvement in compensation using gradient descent and the machine learner over manual compensation. This improvement is inferred from an increase of the fluorescence rate of 78% and 96% respectively, for a trapped \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$^{171}$$\end{document}171Yb\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$^+$$\end{document}+ ion driven by a laser tuned to \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$-7.8$$\end{document}-7.8 MHz of the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$^2$$\end{document}2S\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$_{1/2}\leftrightarrow ^2$$\end{document}1/2↔2P\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$_{1/2}$$\end{document}1/2 Doppler cooling transition at 369.5 nm.

www.nature.com/scientificreports/ central ground electrode for efficient fluorescence collection from the ion 22 . A Gradient descent (ADAM 23 ) and a machine learning algorithm (MLOOP 20 ) were compared on the basis of the versatility and time taken to find the optimal compensation and highest fluorescence rate of the ion. These methods were applied to a trapped 171 Yb + ion and compared to a manual optimization performed by an experienced operator. With ADAM we were able to improve the fluorescence by 78% starting from voltages already optimized by manual adjustment, while MLOOP achieved a 96% improvement. Subsequently we tested the versatility and adaption of this procedure by deliberately charging the trap with UV light to drop the fluorescence rate by around 35% and compensating back to the optimal with ADAM. This was not tested on MLOOP as it was observed to be quite sensitive to the noise in the fluorescence signal and did not make a solid candidate for final optimization of the artificially charged trap.

Experimental setup
The ion trap used in these experiments and described in 22,24 , consists of a planar rectangular chip of 1400 µ m length and 800 µ m width. It has a set of aluminum electrodes patterned on top and is schematically shown in Fig. 1. The ion is trapped 60 µ m above the surface, between the two RF electrode rails that extend for the full length of chip, and 44 DC electrodes on the sides. The DC electrodes are used for creating a reconfigurable The ion is laser cooled on the nearly closed 369.5 nm 2 S 1/2 , F = 1 to 2 P 1/2 , F = 0 transition. The small amount of off-resonant scattering into the 2 S 1/2 F = 0 state is repumped with a 14.7 GHz sideband on the primary cooling laser. Decays from 2 P 1/2 can also populate the 2 D 3/2 level, which are repumped using a 935 nm laser. (b) Schematics of the ion trap chip and the optimization devices. RF and DC electrodes are used to trap the ion and shuttle it above the diffracting mirror that collects photons from the ion and sends it to photo multiplayer tube (PMT). The PMT counts are processed by the optimiser and DC electrode voltages and cooling laser position are updated using a digital to analogue converter (DAC). and laser detuning ( δ ) in the low intensity limit (Eq. 1). For our 370 nm transition the fluorescence rate is proportional to the 2 P 1/2 excited state population. The laser frequency detuning δ = −7.8 MHz, the natural linewidth γ = 20 MHz and the RF trap drive frequency = 25.5 MHz. Heating/cooling dynamics are neglected. Our optimizations occur in the low beta ( < 1 ) limit. (b) The photon count improvement using ADAM starting from manually optimized voltage set weights. This graph demonstrates a 78 ± 1% improvement in ion fluorescence. The error bars are a combination of the readout error of the PMT and peak to peak variations in the photon count whilst not optimizing. The background photon count here is 1184 ± 34 counts/s. www.nature.com/scientificreports/ trapping potential along the length of the trap, compensating stray electric fields, and enabling ion crystals merging, separation, and shuttling. An atomic oven underneath one end of the trap generates a beam of neutral Yb atoms which passes through a slit in the chip. The 171 Yb is first excited by an isotopically selective 399 nm laser 25 , and subsequently nonresonantly ionized by a 369.5 nm laser. The ion is then Doppler cooled using the same 369.5 nm laser tuned nearly resonant with 2 S 1/2 F = 1 ↔ 2 P 1/2 F = 0 transition. To efficiently cool the ion in both x and y directions, the RF axis of the trap is slightly tilted and therefore the horizontal cooling laser has a component along both nearly horizontal x-axis and nearly vertical y-axis. Occasionally off-resonant scattering from the 2 P 1/2 F = 1 state will populate the dark 2 S 1/2 F = 0 ground state, which is repumped by a small amount of light from a 14.7 GHz sideband added to the primary 369.5 nm cooling laser. There is also a probability of 0.5% for the atom to decay from the 2 P 1/2 into the meta-stable 2 D 3/2 state. In this case a 935 nm laser repumps the ions back into the cooling cycle. Figure 1a depicts the cooling and repumping transitions.
After initial trapping near the oven slit region, the ion is shuttled along the length of the trap by properly controlling the voltages of the array of DC electrodes with a 12-bit National Instruments PXI-6713 DAQ (output doubled to +/−20 V with 10 mV resolution). For our experiments, the ion was shuttled above the surface of an integrated diffracting micro-mirror patterned on the ground electrode with a focal length of 60 µ m, equal to the height of the ion above the trap, to improve florescence collection and coupling into a single mode fiber 22 .
For efficient Doppler cooling and subsequent quantum information processing experiments, it is important to minimize any micromotion induced by stray electric fields. This is done by tuning the voltages of the DC electrodes so that they generate an opposing electric field that compensates for the stray fields. To manually compensate stray electric fields in the RF confinement plane xy (see Fig. 1), it is not practical to individually tune all the 44 DC electrodes. We instead use two voltage sets (array of DC voltages for individual electrodes) which were calculated for generating an electric field of 100 V/m in the x (horizontal) and y (vertical) directions. Electrode voltages of −1 to +1 V for the x direction and −2 to +2 V for the y direction are needed to create electric field of 100 V/m at the location of the ion. These sets of voltages are multiplied by arbitrary weights w x and w y to compensate arbitrary fields in the RF trapping plane. In practice this process has imperfections and cannot fully compensate for the stray electric fields 17 . Instead, individual electrodes need to be tuned independently for optimal compensation. This optimum compensation is position dependent and there might be multiple solutions for a multi-electrode trap.
Two other DC voltage sets are used and their relative weights tuned: a harmonic voltage set, and RF plane trap axis rotation voltage set. The former creates a harmonic potential to trap the ion in different locations along the chip length, while the latter rotates the trap's secular confinement axes to lift the degeneracy and improve cooling 26 .
We infer the magnitude of the stray electric field from the fluorescence rate of the ion when the cooling laser is red-detuned near half its natural linewidth for optimal cooling. When driving an ideal cold two-level atom with this laser, the fluorescence is proportional to the population of excited state, P e , that can be calculated from the optical Bloch equation 27 . The relationship between P e and the strength of the stray electric field is given by 15 : where J m is the m th order Bessel function of the first kind, δ L = ω atom − ω laser is the laser frequency detuning, γ is the natural linewidth and is the RF trap frequency. The amount of micromotion is embedded in the dimensionless parameter β which accounts for the dimensionless measure of the ion's coherently driven motion from the stray electric fields and RF phase imbalances (AC micromotion) 15 . C depends on the strength of the coupling between the levels that is a constant here since we keep laser intensity and direction fixed. Figure 2a shows a graph of P e (β)/P e (0) as a function of β . The graph shows that at our detuning ( −7.8 MHz) the population decreases monotonically as β increases if β is less than 2.5. For larger β micromotion induced local maxima arise that prevent inferring the magnitude of micromotion from fluorescence rate. Since our operating regime is below this threshold, we can use the change in fluorescence rate to detect the change in magnitude of the stray electric field.

Results
A gradient descent algorithm (ADAM) and a deep learning network (MLOOP) were tested for compensating stray fields in different working regimes. The source code used for the experiments is available in 28 . The software controlled the voltages using the PXI-6713 DAQ and read the fluorescence counts from a photo-mutliplier-tube (PMT) through a time tagging counter (IDQ id800). All software was written in python and interfaced with the DAQ hardware using the library NI-DAQmx Python. A total of 44 DC electrodes and the horizontal position of the cooling laser were tuned by the program, resulting in a total of 45 input parameters.
Gradient descent optimizer. The first compensation test was performed by ADAM gradient descent algorithm. This is a first order optimizer that uses the biased first and second order moments of the gradient to update the inputs of an objective function, and was chosen for its fast convergence, versatility in multiple dimensions and tolerance to noise 23 . Our goal was to maximize the fluorescence of the ion which was described by a function f ( α ) , where � α = (α 1 , α 2 , α 3 , . . . α 45 ) represents the array of parameters to be optimized. To find the optimal α , the algorithm needs to know the values of the partial derivatives for all input parameters. Because we do not have an analytic expression for f ( α ) , the values of its derivatives were estimated from experimental measurements by sequentially changing each input α i , and reading the associated change in fluorescence f. This data were used as inputs to ADAM for finding the optimal α which maximized f. www.nature.com/scientificreports/ Before running the automated compensation, we manually adjusted the 4 weights of the voltage sets used for compensation described in the previous section. We also tried to run ADAM to optimize these 4 parameters but the increase in fluorescence was limited to 6%. After manual compensation, we ran ADAM on all 45 inputs with the algorithm parameters given in the source code 28 . Each iteration took 12 s, where 9.8 s were the photon readout (0.1 s× 2 readouts per parameter plus 2 ×0.1 s readouts at the beginning and end of the iteration), and the rest of the time was the gradient computation. If the photon count reduced by more than 40% of its initial value, the algorithm terminated and applied the previously found optimum. This acted as the safety net for the program, ensuring the ion was not lost while optimizing the 45 inputs. We need this safety net because if the ion is heated past the capture range for the used cooling detuning, it will be ejected from the trap. In our implementation of the algorithm we removed the reduction in the step size of the optimization algorithm as iterations progressed. This step reduction, which is present in the standard version of ADAM, is not ideal when stray fields change with time since the optimal values of the voltages also drift in time. The removal caused some fluctuations in the photon readout near the optimal settings. Adding to these fluctuations, other sources of noise, such as wavemeter laser locking 32 , and mechanical drift in the trap environment, resulted in daily photon count variations of around 5%. Fluctuation in laser power was not a concern here since the power of the cooling laser was stabilized. Despite these fluctuations, and the fact that stray fields change every day, the algorithm demonstrated an increase in fluorescence collection up to 78 ± 1% (Fig. 2b) when starting from a manually optimized configuration in less than 10 iterations, or 120 s.
The ADAM algorithm was fast and reliable (the ion was never lost during optimization), even in extremely volatile conditions like having time-dependent charging and stray electric field buildup. Figure 3a shows a colourmap of the voltages and laser position adjustments, where most of the improvement came from adding the same voltage to all DC electrodes indicating that the ion was not at optimal height. The volatility of the ion-trap environment causes the fluorescence rate to oscillate around the optimal point. To get the best value, instead of using the values of the final iteration, the software saved all voltage combinations and applied the setting with the highest photon count after all iterations were finished. Despite picking the best value it can be seen in Fig. 2b that the fluorescence for some iterations during the optimization are higher than the final point selected by the software. This is because when the settings are changed, the ion fluorescence rate may transiently increase and subsequently stabilize to a slightly lower value for the same voltage settings.
Deep learning network for the ion trap. The second algorithm tested was a deep learning network using the python based optimization and experimental control package MLOOP 20 . MLOOP uses Differential Evolution 33 for exploring and sampling data. The blue points in Fig. 4a corresponds to these samples and it can be seen that even at the end of optimization, they can have non-optimum fluorescence rates. MLOOP also trains a neural network using the data collected by Differential Evolution and creates an approximate model of the experimental system. It then uses this model to predict an optimum point. The red points in Fig. 4a shows the optimum points predicted by the neural network model. It can be seen that this section starts later than Differential Evolution, as it requires some data for initial neural network training, and gradually finds the optimum and stays near it. For training of the neural network, the inbuilt ADAM optimizer is used to minimize the cost function. The sampling in MLOOP does not require a gradient calculation which greatly improves the sampling time. Even though the sampling is fast, training the network to find an optimal point requires a minimum of 100 samples and that makes MLOOP slower than ADAM. With our settings for MLOOP, each iteration took 0.7 s on average and therefore 700 s was needed to take 1000 samples shown in Fig. 4a. www.nature.com/scientificreports/ In our test the neural network in MLOOP had 5 layers with 45 nodes each, all with Gaussian error correction. The neural network structure (number of layers and cells) was manually optimized and tested on a 45-dimensional positive definite quadratic function before being used for the experiment. Once the ion was trapped, positioned above the integrated mirror 22 , and photon counts were read, the program started sampling 100 different voltage combinations around its initial point. Then, the network started training on the initial data and making predictions for the voltages that maximise fluorescence. Since the ion trap setup is very sensitive to changes in the electric field, the voltages were set to move a maximum of 1% of their previous value in each iteration to reduce the chance of losing the ion. As a step size value could not be explicitly defined, this percentage was chosen to make the changes similar to the step size used for ADAM.
A small percentage of our initial trials with the maximum change of a few percent (instead of 1%) led to an unstable ion during the parameter search sequence. This is because MLOOP is a global optimizer and can set the voltages to values far from the stable starting point. Since the ion trap is a complicated system that can only be modelled for a specific range of configurations, moving away from these settings can lead to unpredictable and usually unstable behavior. MLOOP also has an in-built mechanism that handles function noise using a predefined expected uncertainty. We set this uncertainty to the peak-to-peak noise of the photon readout when no optimization was running.
Since MLOOP is a global optimizer it was able to find optimum points different from the points found by ADAM. For trials where low numbers of initial training data points were used, these configurations proved to be unstable and in most cases resulted in the loss of the ion. Unstable states were also observed occasionally if the optimizer was run for too long. With moderate-size training sets, MLOOP was able to find voltage settings with fluorescence rates similar or higher than optimum points found by ADAM as shown in Fig. 4a. Considering the long duration of the MLOOP iteration sequence and the possibility of finding unstable settings in volatile conditions, the test of optimization with induced changing stray fields ("Testing under poor trap conditions") was only performed with the ADAM optimizer as the gradient based search method proved to be more robust against fluctuations in the ion environment.
To test the effectiveness of the protocols, the saturation power, P sat , was measured before and after the optimization process. The P sat is the laser power at which the fluorescence rate of a two-level system is half the fluorescence at infinite laser power. We also measured the overall detection efficiency η , the fraction of emitted photons which resulted in detection events. Table 1 shows P sat decreased (ion photon absorption was improved) using both ADAM and MLOOP. The detection efficiency was approximately the same for all runs as expected.
Another test was done by measuring fluorescence versus laser detuning before and after optimization. Figure 4b shows that the measured values follows the expected Lorentzian profile [29][30][31] and associated linewidth before and after optimization. This indicates that the initial micromotion magnitude β was sufficiently small for fluorescence to be a good optimization proxy. Clear increase in florescence can be seen after optimizing 44  Figure 4. (a) MLOOP deep learning network. Differential Evolution explores the input space (blue points) and the neural network creates a model of the data and predicts an optimum (red points). Maximum photon count of the neural network points is 96 ± 1% higher than manual optimization. Differential Evolution continues to explore the input space and has varied photon counts. The beginning point for the process (found by manually adjusting the 4 voltage set weights) was at 33700 counts/s and the highest photon count found by the neural network was at 66200 counts/s. (b) and (c) Fluorescence versus laser frequency detuning from the resonance for inital setting and after different optimizations. It can be seen from that the experimental values are very close to the theoretical Lorentzian fit [29][30][31] . This shows the heating is low before and after optimization and therefore the change in fluorescence can be used to infer the change in heating. Deviation from the theory near the resonance shown in (b) is a sign of small heating instability. Testing under poor trap conditions. To test the live performance of the optimization protocol in a nonideal situation, we deliberately charged the trap by shining 369.5 nm UV laser light onto the chip for 70 min. The power of the laser was 200 ± 15µW and the Gaussian diameter of the focus was 120 ± 10µm . This process ejects electrons due to the photo-electric effect 34 and produces irregular and potentially unpredictable slow time varying electric fields within the trap. The process charged the trap significantly and made a noticeable reduction to the photon count. The ADAM algorithm was then tested both during charging and after charging was stopped.
In both cases an improvement of fluorescence rate was observed. The first experiment was performed to test the optimizing process after charging. In this test, starting with the optimal manual setting, ADAM individual electrode optimizer was able to obtain 27% improvement in the fluorescence rate (blue points on the left side of Fig. 5a). Then charging was induced onto the trap for 70 min and a clear decrease in photon count was seen that went even lower than the initial value (red points in Fig. 5a). At this point charging was stopped and ADAM was run again and fluorescence rate returned back to the previous optimum, within the error, in approximately 12 min. During the second optimization, the fluorescence goes higher than the stable final value for some iterations before the final. This is because of the same effect explained in "Gradient descent optimizer" section that the fluorescence might spike right after a change but go down slightly after stabilizing. Looking at the changes of individual electrodes, shown in Fig. 3b, we see that the main electrodes adjusted were those around the ion and some throughout the trap. The change in the laser horizontal position was negligible.
Another experiment was done by running ADAM during continuous charging for real-time compensation. Since we induce charging via laser scattering from the trap, the collected photons are both from the ion and the scattered laser and fluctuations in the intensity of scattered light confuses the optimizer. Despite that the optimizer did not lose the ion nor needed to abort the process. Figure 5b shows that the fluorescence rate, even after Table 1. Saturation power ( P sat ), detection efficiency ( η ) and average background count rate (Bkg) before and after optimization with different methods. P sat and η values are calculated by fitting the theoretical formula for Fluorescence Rate versus Laser Power to the experimental data [29][30][31] . A clear drop in saturation power is observed after ADAM and MLOOP optimization of individual electrodes indicating a reduction of the micromotion.  www.nature.com/scientificreports/ a 70-min charging session, remained near the optimum value. After stopping the charging, the ion remained trapped for more than 8 h and was intentionally removed from the trap after this time.

Conclusion
Comparing the results of the gradient descent method and MLOOP shows that ADAM, the local optimizer, was a better performer in volatile conditions. This is because unlike MLOOP, ADAM does not need any training and can react faster to changes. MLOOP as a global optimizer was able to find settings with higher fluorescence but occasionally optimums were unstable if the defined parameter search range for the settings were large or if the machine learner ran for too long. The main drawback of MLOOP was that it was much slower than ADAM. In both cases photon collection times were the limiting factor. Optimizing the individual electrodes improved the fluorescence by 78% for ADAM and 96% for MLOOP. ADAM showed its reliability in the charging test, returning the ion to the optimal fluorescence in 12 min after 70 min of purposely charging the trap with a UV laser. Improvement amounts depended greatly on the overall stability of the cooling laser and efficiency of the photon counting system.
To improve the speed of the gradient based optimizer, shorter readout times can be used although this increases variability in the value of the photon count. It is also possible to try local optimizers like SPSA 35 that approximate the gradient using only 2 readouts instead of 90. This improves the time needed for each iteration but because using this approximate gradient reduces the improvement in each iteration, the overall speed comparison to reach the same optimum can only be made when both are tried in practice. One possible problem with SPSA is that it cannot handle noise like ADAM and multiple readouts and averaging are needed in noisy conditions. If high amount of averaging is required, the algorithm may become very slow.